package ex.tableapi;

import org.apache.flink.table.api.Table;

import static org.apache.flink.table.api.Expressions.$;

/**
 * https://nightlies.apache.org/flink/flink-docs-release-1.18/docs/dev/table/tableapi/#groupby-aggregation
 */
public class Ex02  extends ApiFrame {
	private String outName = "printOutTable";
	private    String createPrintOutDDL = "CREATE TABLE printOutTable (" +
            "a STRING, " +
            "d BIGINT " +
            ") WITH (" +
            " 'connector' = 'print' " +
            ")";
	
	public static void main(String[] args) {
		Ex02 demo =new Ex02();
		demo.getEnv();
		Table orders = demo.registerMysql("myorder", "orders");
		 demo.registerConsole(demo.createPrintOutDDL,demo.outName);			
		
		 Table result = orders.groupBy($("a")).select($("a"), $("b").sum().as("d"));

		result.printSchema();
	      result.executeInsert(demo.outName);	        
	   	}
}
